"""
APIDeej您需要的基本模型.
TODO: 需要按角色进行重新配置工作.
"""
from datetime import datetime
from enum import Enum

from sqlalchemy import Column, DateTime, ForeignKey, Integer, String

from core.database import DBConnect
from core.models import Base, DB_TABLE_PREFIX


class MemberRefreshToken(Base):
    # “会员Refresh Token表格模型”
    __tablename__ = DB_TABLE_PREFIX + "member_refresh_token"

    id = Column(Integer, primary_key=True, index=True)
    mb_id = Column(String(20), index=True, nullable=False, default="") # ForeignKey(DB_TABLE_PREFIX + "member.mb_id")
    refresh_token = Column(String(255), unique=True)
    expires_at = Column(DateTime, default=datetime.now) # Refresh Token的到期时间.
    created_at = Column(DateTime, default=datetime.now)
    updated_at = Column(DateTime, default=datetime.now)

# MemberRefreshToken 表创建
# TODO: 
#   1. 需要担心何时创建表
#       - 安装时是否一起做
#       - API如果要在设置使用选项等时创建..
#   2. 已过期 Refresh Token需要定期删除
MemberRefreshToken.__table__.create(bind=DBConnect().engine, checkfirst=True)


class Tags(Enum):
    """API 我们定义了标签."""
    AUTH = "认证"
    BOARD = "公告板"
    CAPTCHA = "盖茶"
    GROUP = "公告板组"
    CONFIG = "环境设置"
    CONTENT = "内容"
    FAQ = "FAQ"
    MEMBER = "成员"
    MEMO = "备注"
    MENU = "菜单"
    NEWWIN = "弹出层"
    CURRENT_CONNECT = "当前访问"
    POINT = "点"
    POLL = "调查"
    POPULAR = "热门搜索词"
    QA = "Q&A"
    SCRAP = "废料"
    SEARCH = "搜索"
    BOARD_NEW = "最新写作"
    AJAX_AUTOSAVE = "自动存储"
    AJAX_GOOD = "好吧./我不喜欢."
    VISIT = "访客"
